using UnityEngine;
using System.Collections;

/// \class  gkCylinderTubeInfo
/// \brief  Info on the current world cylinder tube
[AddComponentMenu("GK/Engine/Game/CylinderTube/gkCylinderTubeInfo")]
[RequireComponent (typeof (gkVelocityController))]
[RequireComponent (typeof (gkPhysicComponent))]
[RequireComponent (typeof (gkBoostComponent))]
public class gkCylinderTubeInfo : MonoBehaviour 
{
    /// The radius in volume game percent
    public float RadiusGameVolumePercent = 0.75f;
	
	/// Color unselected
    public Color SelectedColor = new Color(0.0f, 0.0f, 0.75f, 0.5f);

    /// Color unselected
    public Color UnselectedColor = new Color(1.0f, 1.0f, 1.0f, 0.5f);
	
	/// The radius
    private float m_fRadius;

    /// \brief  Called just after the game begin to play
    void Awake()
    {
		Bounds oGameVolumeBoudingBox;
		
        // Get the game volume bounding box
        gkUtilityBounds.GrabColliderOrRendererBounds(GameObject.Find("GameVolume"), out oGameVolumeBoudingBox);
		
		// Compute the radius
		m_fRadius = oGameVolumeBoudingBox.extents.y;
    }
	
	/// \brief  Called each frame
    void OnDrawGizmos()
    {
        // In editor always draw the bounding box
        if (Application.isEditor)
        {			
			// Draw the cylinder tube
            DrawCylinderTubeBounds(UnselectedColor);
        }
    }

    /// \brief  Called each frame
    void OnDrawGizmosSelected()
    {
        // In editor always draw the bounding box
        if (Application.isEditor)
        {
            // Draw the cylinder tube
            DrawCylinderTubeBounds(SelectedColor);
        }
    }
	
	/// \brief  Get the radius
	public float GetRadius()
	{
		return m_fRadius;
	}
	
	/// \brief  Draw the bounds
	void DrawCylinderTubeBounds(Color a_oColor)
	{	
		Bounds oGameVolumeBoudingBox;
		Vector3 f3BoundsSize;
		
		// Get the game volume bounding box
		gkUtilityBounds.GrabColliderOrRendererBounds(GameObject.Find("GameVolume"), out oGameVolumeBoudingBox);
		
		// Take the corresponding tube portion of the game volume
		f3BoundsSize = oGameVolumeBoudingBox.size;
		f3BoundsSize.y *= RadiusGameVolumePercent;
		f3BoundsSize.x = f3BoundsSize.y;
		
		// Draw the bounds
        Gizmos.color = a_oColor;
        Gizmos.DrawWireCube(oGameVolumeBoudingBox.center, f3BoundsSize);
	}
}

